package com.example.elmspringboot.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.elmspringboot.domain.Business;
import com.example.elmspringboot.mapper.FoodMapper;
import com.example.elmspringboot.domain.Food;
import com.example.elmspringboot.service.FoodService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FoodServiceImpl extends ServiceImpl<FoodMapper, Food> implements FoodService {
    @Resource
    private FoodMapper foodMapper;

    @Override
    public IPage<Food> getPage(int currentPage, int pageSize, Food food) {
        IPage page=new Page(currentPage,pageSize);
        LambdaQueryWrapper<Food> wrapper=new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(food.getName()), Food::getName, food.getName());
        wrapper.like(Strings.isNotEmpty(food.getDescription()), Food::getDescription, food.getDescription());
        wrapper.eq(true,Food::getShopId,food.getShopId());
        return foodMapper.selectPage(page,wrapper);
    }

    @Override
    public List<Food> getFoodByBusinessID(Integer shopId) {
        LambdaQueryWrapper<Food> wrapper=new LambdaQueryWrapper<>();
        return foodMapper.selectList( wrapper.eq(true ,Food::getShopId, shopId));
    }
}
